<?php

namespace app\store\controller\market;

use app\store\controller\BaseController;
use app\store\service\IntegralSettingService;
use think\exception\ValidateException;
use think\facade\View;

class IntegralController extends BaseController
{
    public function setting()
    {
        if ($this->request->isGet()){

            $row = IntegralSettingService::findBaseSetting();
            return View::fetch('',['row' => $row]);
        }

        if ($this->request->isPost()){
            $param = $this->request->param();

            try {
               validate('IntegralSettingValidate')->check($param);
            }catch (ValidateException $e){
                return json(['code' => 0, 'msg' => $e->getMessage()]);
            }
            if (!empty($param['sign_in_config'])){
                $param['sign_in_config'] = IntegralSettingService::formatSignInConfig($param['sign_in_config']);
            }else {
                $param['sign_in_config'] = null;
            }


            IntegralSettingService::saveBaseSetting($param);
            return  json(['code' => 1,'msg' => '保存成功']);
        }
    }
}